package com.example.handler

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler
import mu.KotlinLogging
import org.apache.ibatis.reflection.MetaObject
import org.springframework.stereotype.Component
import java.time.LocalDateTime

val log = KotlinLogging.logger {}

@Component
class TimeAutofillHandler: MetaObjectHandler {
    override fun insertFill(metaObject: MetaObject?) {
        log.info("insert自动填充..........")
        this.strictInsertFill(metaObject, "createTime", LocalDateTime::class.java, LocalDateTime.now())
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::class.java, LocalDateTime.now())
    }

    override fun updateFill(metaObject: MetaObject?) {
        log.info("update自动填充..........")
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::class.java, LocalDateTime.now())
    }

}